# -*- coding: utf-8 -*-

import serial
import queue
import time
from datetime import datetime


com_name = "COM1"               # 串口号
output_path = ''                # 保存路径
video_queue = queue.Queue()     # 列队

ser = serial.Serial(com_name, 115200, timeout=2)

while True:
    if ser.isOpen():
        while True:
            start = time.time()
            data1 = ser.readline().strip()
            # 判断是否为数字
            if data1.isdigit():
                num1 = int(data1)
                print("已接收到整数：", num1)
                video_queue.queue.clear()
                end = time.time() - start
                print(f'时间差为：{end}')
                if 0 <= num1 <= 2 or 357 < num1 <= 359:
                    print("接收到非整数数据：%s" % data1.decode())
                    break
            else:
                print("接收到非整数数据：%s" % data1.decode())
                video_queue.put(data1.decode())
    print('串口通信成功')

    while not video_queue.empty():
        print(video_queue.get())
    else:
        print(f'列队为空')
